package com.android.love.adapter;

import java.util.Collections;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.love.R;
import com.android.love.util.Constant;
import com.android.love.util.ImageUtils;
import com.android.love.util.LogUtil;
import com.android.love.vo.SingleGoods;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;

public class OrderDetailAdapter extends BaseAdapter implements Constant {
	private static final String TAG = "CommentAdapter";
	private ImageLoader loader;
	private List<SingleGoods> goods = Collections.emptyList();;
	private Context context;

	// private Handler handler;

	public OrderDetailAdapter(Context context, ImageLoader loader,
			List<SingleGoods> goods) {
		super();
		this.context = context;
		this.loader = loader;
		this.goods = goods;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return goods.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return goods.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// ViewHolder holder;
		// if (convertView == null) {
		convertView = View.inflate(context, R.layout.order_detail_item, null);
		// holder = new ViewHolder();
		ImageView iv_cart_img = (ImageView) convertView
				.findViewById(R.id.iv_cart_img);
		TextView tv_cart = (TextView) convertView.findViewById(R.id.tv_cart);
		TextView tv_format = (TextView) convertView
				.findViewById(R.id.tv_format);
		final TextView tv_price = (TextView) convertView
				.findViewById(R.id.tv_price);
		final TextView tv_num = (TextView) convertView
				.findViewById(R.id.tv_num);
		TextView tv_id = (TextView) convertView.findViewById(R.id.tv_id);
		// convertView.setTag(holder);
		// } else {
		// holder = (ViewHolder) convertView.getTag();
		// }
		// Goods good = new Goods();
		final SingleGoods good = goods.get(position);
		tv_cart.setText(good.getGoods_name());
		tv_price.setText("￥" + good.getPrice() * good.getCount() + "");
		tv_id.setText("编号:" + good.getGoods_id());
		tv_num.setText(good.getCount() + "");

		tv_format.setText(good.getAttribute());
		loader.displayImageForSize(good.getGoods_image(), iv_cart_img,
				ImageUtils.getOptions(R.drawable.zw2),
				new SimpleImageLoadingListener(), 8, 0, 0, 0, 0, 0, 5f, true);
		return convertView;
	}

	// /**
	// * 发消息
	// *
	// * @param what
	// * @param position
	// */
	// private void sendMessage(int what, int position) {
	// Message msg = Message.obtain();
	// msg.what = what;
	// msg.arg1 = position;
	// handler.sendMessage(msg);
	// }

	// public static class ViewHolder {
	// CheckBox checkBox;
	// ImageView iv_cart_img;
	// ImageView iv_add;
	// ImageView iv_reduce;
	// TextView tv_cart;
	// TextView tv_format;
	// TextView tv_price;
	// TextView tv_num;
	// TextView tv_id;
	// }

}
